package com.kezesong.leasing.controller;

import com.kezesong.leasing.common.ResponseResult;
import com.kezesong.leasing.common.enums.ReturnCodeEnum;
import com.kezesong.leasing.common.exception.CommonException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

@Controller
public abstract class BaseController {

    protected Logger logger = LoggerFactory.getLogger(getClass());
    protected static <T>ResponseResult<T> buildSucessResponse(T data){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setData(data);
        return responseResult;
    }

    protected static ResponseResult<Integer> buildSucessResponse(){
        ResponseResult<Integer> responseResult = new ResponseResult<>();
        responseResult.setReturnCode(ReturnCodeEnum.SUCCESS.getCode());
        responseResult.setReturnMsg(ReturnCodeEnum.SUCCESS.getDesc());
        return responseResult;
    }

    protected static ResponseResult<String> buildFailedResponse(){
        ResponseResult<String> responseResult = new ResponseResult<>();
        responseResult.setReturnCode(ReturnCodeEnum.FAILED.getCode());
        responseResult.setReturnMsg(ReturnCodeEnum.FAILED.getDesc());
        return responseResult;
    }

    protected static ResponseResult<String> buildFailedResponse(CommonException commonException){
        ResponseResult<String> responseResult = new ResponseResult<>();
        responseResult.setReturnCode(commonException.getResponseCode());
        responseResult.setReturnMsg(commonException.getResponseMsg());
        return responseResult;
    }

    protected static <T>ResponseResult<T> buildFailedResponse(ReturnCodeEnum returnCodeEnum, String remark){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setReturnCode(returnCodeEnum.getCode());
        responseResult.setReturnMsg(returnCodeEnum.getDesc() +" " + remark);
        return responseResult;
    }

    protected static <T>ResponseResult<T> buildNoDataResponse(){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
        responseResult.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
        return responseResult;
    }
}
